package com.ruoyi.assets.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.assets.domain.AssetMethods;
import com.ruoyi.assets.service.IAssetMethodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产信息Controller
 * 
 * @author 孙帆科
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/methods")
public class AssetMethodsController extends BaseController
{
    @Autowired
    private IAssetMethodsService assetMethodsService;

    /**
     * 查询资产信息列表
     */
    @RequiresPermissions("assets:methods:list")
    @GetMapping("/list")
    public TableDataInfo list(AssetMethods assetMethods)
    {
        startPage();
        List<AssetMethods> list = assetMethodsService.selectAssetMethodsList(assetMethods);
        return getDataTable(list);
    }

    /**
     * 导出资产信息列表
     */
    @RequiresPermissions("assets:methods:export")
    @Log(title = "资产信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetMethods assetMethods)
    {
        List<AssetMethods> list = assetMethodsService.selectAssetMethodsList(assetMethods);
        ExcelUtil<AssetMethods> util = new ExcelUtil<AssetMethods>(AssetMethods.class);
        util.exportExcel(response, list, "资产信息数据");
    }

    /**
     * 获取资产信息详细信息
     */
    @RequiresPermissions("assets:methods:query")
    @GetMapping(value = "/{methodsId}")
    public AjaxResult getInfo(@PathVariable("methodsId") Long methodsId)
    {
        return success(assetMethodsService.selectAssetMethodsByMethodsId(methodsId));
    }

    /**
     * 获取资产信息详细信息
     */
//    @RequiresPermissions("assets:methods:query")
    @GetMapping(value = "/getMethodsCategoriesInfo/{cateoriesId}")
    public AjaxResult getMethodsCategoriesInfo(@PathVariable("cateoriesId") Long cateoriesId)
    {
        AssetMethods assetMethods = assetMethodsService.selectMethodsCategoriesByMethodsId(cateoriesId);
        System.out.println("数据----"+assetMethods);
        return success(assetMethods);
    }

    /**
     * 新增资产信息
     */
    @RequiresPermissions("assets:methods:add")
    @Log(title = "资产信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetMethods assetMethods)
    {
        return toAjax(assetMethodsService.insertAssetMethods(assetMethods));
    }

    /**
     * 修改资产信息
     */
    @RequiresPermissions("assets:methods:edit")
    @Log(title = "资产信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetMethods assetMethods)
    {
        return toAjax(assetMethodsService.updateAssetMethods(assetMethods));
    }

    /**
     * 删除资产信息
     */
    @RequiresPermissions("assets:methods:remove")
    @Log(title = "资产信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{methodsIds}")
    public AjaxResult remove(@PathVariable Long[] methodsIds)
    {
        return toAjax(assetMethodsService.deleteAssetMethodsByMethodsIds(methodsIds));
    }
}
